//
//  XS_BaseTCell.swift
//  Alamofire
//
//  Created by 韩云智 on 2020/7/15.
//

import UIKit
import RxCocoa
import RxSwift

open class XS_BaseTCell: UITableViewCell {
    open lazy var disposeBag = DisposeBag()
    open lazy var reuseDisposeBag = DisposeBag()
    //单元格重用时调用
    open override func prepareForReuse() {
        super.prepareForReuse()
        reuseDisposeBag = DisposeBag()
    }
    
    open lazy var line = UIView() // 自定义Cell分割线
    
    deinit {
        xsDebug { print("deinit: \(type(of: self))") }
    }
    public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        xsDebug { print("init: \(type(of: self))") }
        upView()
    }
    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    open func upView() {
        selectionStyle = .none // 去掉点击样式
        backgroundColor = .white // 背景色为白色
    }
    
    open func getLineEdgeInsets() -> UIEdgeInsets { // 子类重写可以改变分割的位置
        return UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 0)
    }
    open func loadLine() { // 分割线样式
        let lineEdgeInsets = getLineEdgeInsets()
        line.backgroundColor = #colorLiteral(red: 0.9294117647, green: 0.9294117647, blue: 0.9294117647, alpha: 1)
        addSubview(line)
        line.snp.makeConstraints { maker in
            maker.bottom.equalToSuperview().offset(lineEdgeInsets.bottom)
            maker.right.equalToSuperview().offset(lineEdgeInsets.right)
            maker.left.equalToSuperview().offset(lineEdgeInsets.left)
            maker.height.equalTo(1 + lineEdgeInsets.top)
        }
    }
    
    open override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    open override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }

}
